package com.org.flow.system.service.impl;

import com.org.flow.system.mapper.LinkInfoMapper;
import com.org.flow.system.model.dos.log.LinkInfoDTO;
import com.org.flow.system.service.LinkService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import java.util.Date;

@Service
@RequiredArgsConstructor
@Slf4j
public class LinkServiceImpl implements LinkService {

    private final LinkInfoMapper linkInfoMapper;

    /**
     * 方法描述：用来模拟业务执行
     *
     * @since 1.0.0   2024-02-26 09:50:19
     */

    @Override
    public boolean process(String linkCode, String linkName) {
        LinkInfoDTO dto = new LinkInfoDTO();
        dto.setLinkCode(linkCode);
        dto.setLinkName(linkName);
        dto.setLinkDesc("环节描述");
        dto.setCreateUser("张三");
        dto.setUpdateTime(new Date());
        int row = linkInfoMapper.insertSelective(dto);
        if ("lite_other_star".equals(linkName)) {
            return false;
        }
        return row > 0;
    }

    @Override
    public void transactionTesting(String linkCode, String linkName) {
        if (TransactionSynchronizationManager.isActualTransactionActive()) {
            log.info(" Transaction started and  survival .....");
            String txName = TransactionSynchronizationManager.getCurrentTransactionName();
            log.info(" ############## this transaction name is: {}.", txName);
            log.info("transactionTesting  的线程：" + Thread.currentThread().getName());
        }else{
            log.info(" Transaction not initialize and survival ....");
        }
        process(linkCode, linkName);
    }

    @Override
    public boolean transactionTesting1(String linkCode, String linkName) {
        return false;
    }
}
